// Copyright (C) 2010 Razvan Constantin <razvan.constantin@rconst.net>
//
// This file is part of FileBow.
//
// FileBow is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// FileBow is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with FileBow.  If not, see <http://www.gnu.org/licenses/>.

#ifndef FILEBOW_UTILS_NPATH_H__
#define FILEBOW_UTILS_NPATH_H__

#include <string>

#include <Poco/File.h>
#include <Poco/Path.h>

#include "common/common.h"

/**
 * Wrapper around Poco::Path and the filesystem node associated to the path.
 */
class NPath {

  /** Constructors. */
  public: explicit NPath(const char* path);
  public: explicit NPath(const std::string& path);
  public: explicit NPath(const Poco::Path& path);
  private: void Init(const Poco::Path& path);

  // Allow copying.
  public: NPath(const NPath& npath);
  public: NPath& operator=(const NPath& npath);

  // Properties.
  public: bool valid() const { return mPath.isFile(); }
  public: const std::string& node() const { return mPath.getFileName(); }
  public: const Poco::File& handle() const { return mFile; }

  // String representation.
  public: std::string ToString() const { return mPath.toString(); }

  // Navigation.
  public: void Up();
  public: void Down(const std::string& node);

  // Operations.
  public: void ReadLink();

  /** The actual path. Normalized (has filename) and absolute. */
  private: Poco::Path mPath;

  /** File for path. */
  private: Poco::File mFile;
};

#endif // FILEBOW_UTILS_NPATH_H__
